local skel = fk.CreateSkill{
  name = "tea__calm_elixir_skill",
  tags = { Skill.Compulsory },
  attached_equip = "tea__calm_elixir"
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  [":tea__calm_elixir_skill"] = "锁定技，当你失去体力时，防止之（每回合限一次）；当你成为黑色牌的目标后，若你已受伤，你弃置装备区里的【安神丹】或重铸三张红色手牌，然后回复1点体力。",
  ["#tea__calm_elixir-choose"] = "安神丹：选择三张红色手牌重铸，或点取消选择弃置【安神丹】",
}
---@type TrigSkelSpec<HpLostTrigFunc>
local calm_elixir_skill = {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and player:getMark("tea__calm_elixir-turn") == 0
  end,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "tea__calm_elixir-turn", 1)
    data:preventHpLost()
  end
}
---@type TrigSkelSpec<AimFunc>
local calm_elixir_skill_aim = {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and data.card and data.card.color == Card.Black and player:isWounded()
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local suc
    if #player:getCardIds("h") >= 3 then
      local cards = room:askToCards(player, {
        min_num = 3,
        max_num = 3,
        skill_name = skel.name,
        pattern = ".|.|diamond,heart",
        prompt = "#tea__calm_elixir-choose",
      })
      if #cards == 3 then
        room:recastCard(cards, player, skel.name)
        suc = true
      end
    end
    if not suc then
      local equip = table.find(player:getCardIds("e"), function (id)
        return Fk:getCardById(id).name == "tea__calm_elixir"
      end)
      if equip then
        room:throwCard(equip, skel.name, player, player)
      end
    end
    if not player.dead and player:isWounded() then
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name
      }
    end
  end
}
skel:addEffect(fk.PreHpLost, calm_elixir_skill)
skel:addEffect(fk.TargetConfirmed, calm_elixir_skill_aim)
return skel